<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
session_start();

require_once 'includes/connect.php';
require_once 'includes/function.php';

$db = new myDBS();

$task = $_REQUEST["task"];

$id = $_REQUEST["id"];
//$pet_id = $_REQUEST["pet_id"];

$budget_year = $_REQUEST["budget_year"];
$panngan2_id = $_REQUEST["panngan2_id"];
$panngan3_id = $_REQUEST["panngan3_id"];
$ex1_id = $_REQUEST["ex1_id"];
$ex2_id = $_REQUEST["ex2_id"];
$month_year = $_REQUEST["month_year"];
$amount = $_REQUEST["amount"];
$tax = $_REQUEST["tax"];
$tax1 = $_REQUEST["tax1"];
$tt = $_REQUEST["tt"];
$tt1 = $_REQUEST["tt1"];
$penalty = $_REQUEST["penalty"];
$net = $_REQUEST["net"];
$lvl1_id = $_SESSION["lvl1_id"];

$cancel_date = $_REQUEST["cancel_date"];
$cancel_reason = $_REQUEST["cancel_reason"];

$i_date = $_REQUEST["i_date"];
$payment_method = $_REQUEST["payment_method"];

$cheque_no = $_REQUEST["cheque_no"];
$branch_name = $_REQUEST["branch_name"];
$bank_name = $_REQUEST["bank_name"];

$val = $_REQUEST["val"];

$val1 = explode(",", $val);
$val1 = implode("','", $val1);
//$verify_reason = $_REQUEST["verify_reason"];
//echo "xxxx".$_SESSION["lvl1_id"];

switch ($task) {
    case "verify":
        $sql = "UPDATE tbl_pet SET verify_status = 'ผ่าน'"
                . ", verify_date = '$i_date' "
                . ", payment_method = '$payment_method'  "
                . " WHERE id = '$id'";
        $db->runSQL($sql) or die(mysql_error());

        break;
    case "cancel":
        $sql = "UPDATE tbl_pet "
                . " SET status = 'ยกเลิก' "
                . ", cancel_reason = '$cancel_reason' "
                . ", cancel_date = '$cancel_date' "
                . " WHERE  id = '$id'";

        $db->runSQL($sql) or die(mysql_error());

        break;
    case "approved":

        $sql = "UPDATE tbl_pet "
                . "SET approved_status = 'อนุมัติ'"
                . ", approved_date = '$i_date'  "
//                . ", payment_method = '$payment_method'  "
                . " WHERE  id = '$id'";

        $db->runSQL($sql) or die(mysql_error());

        break;
    case "disapproval":
        $sql = "UPDATE tbl_pet "
                . "SET approved_status = 'ไม่อนุมัติ'"
                . ", approved_date = NOW() "
                . " WHERE  id = '$id'";

        $db->runSQL($sql) or die(mysql_error());

        break;
    
    case "confirm":
        
        $budget_year = (date("Y") < 2556)?  date("Y") + 543: date("Y");
        
        $finance_id = get_running_finance($budget_year);
        
        $sql = "UPDATE tbl_pet "
                . "SET confirm = 'ยืนยัน'"
                . ", finance_id = '$finance_id' "
                . " WHERE  id = '$id'";

        $db->runSQL($sql) or die(mysql_error());

        break;
//    case "print":
//        $sql = "UPDATE tbl_pet "
//                . "SET cheque_no = '$cheque_no'"
//                . ", branch_name = '$branch_name'"
//                . ", bank_name = '$bank_name'"
//                . ", cheque_prt_date = '$i_date' "
//                . "WHERE pet_id in('$val1')";
//        
//        echo $sql;
//        $db->runSQL($sql) or die(mysql_error());
//        break;
//    case "approvedCheque":
//        $sql = "UPDATE tbl_pet SET cheque_status = 'อนุมัติ', cheque_date = '$i_date' WHERE cheque_no = '$cheque_no'";
//
//        break;
//    case "disapprovalCheque":
//
//        $sql = "UPDATE tbl_pet SET cheque_status = 'ไม่อนุมัติ' WHERE cheque_no = '$cheque_no'";
//        break;
//    case "print":
//        $sql = "UPDATE tbl_pet SET cheque_no = '$cheque_no', branch_name = '$branch_name', bank_name = '$bank_name', cheque_date = '$i_date' WHERE pet_id in('$val1')";
//
//        break;
//    case "paid":
//        $sql = "UPDATE tbl_pet SET paid_status = 'จ่ายแล้ว', paid_date = NOW() WHERE cheque_no = '$cheque_no'";
//        break;

    default:
        break;
}
?>

